/*
 * Copyright (C) 2014 Steven Kurilovitch
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.goodjaerb.swccg.ui;

import com.goodjaerb.swccg.core.CardData;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 *
 * @author Steven Kurilovitch
 */
public class SideFilterPanel extends javax.swing.JPanel {

    /**
     * Creates new form SideFilterPanel
     */
    public SideFilterPanel() {
        super();
        initComponents();
        
        ItemListener il = (ItemEvent e) -> {
            if(e.getStateChange() == ItemEvent.DESELECTED) {
                if(e.getSource() == lightCheckbox) {
                    if(!darkCheckbox.isSelected()) {
                        darkCheckbox.setSelected(true);
                    }
                }
                else {
                    if(!lightCheckbox.isSelected()) {
                        lightCheckbox.setSelected(true);
                    }
                }
            }
        };
        
        lightCheckbox.addItemListener(il);
        darkCheckbox.addItemListener(il);
    }
    
    public void addItemListener(ItemListener il) {
        lightCheckbox.addItemListener(il);
        darkCheckbox.addItemListener(il);
    }
    
    public void setSelected(boolean light, boolean dark) {
        lightCheckbox.setSelected(light);
        darkCheckbox.setSelected(dark);
    }
    
    public boolean bothSelected() {
        return lightCheckbox.isSelected() && darkCheckbox.isSelected();
    }
    
    public String getSelectedSide() {
        if(!bothSelected()) {
            return lightCheckbox.isSelected() ? CardData.Side.LIGHT.toString() : CardData.Side.DARK.toString();
        }
        return null;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lightCheckbox = new javax.swing.JCheckBox();
        darkCheckbox = new javax.swing.JCheckBox();

        lightCheckbox.setSelected(true);
        lightCheckbox.setText("Light");

        darkCheckbox.setSelected(true);
        darkCheckbox.setText("Dark");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lightCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
            .addComponent(darkCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(lightCheckbox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(darkCheckbox))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox darkCheckbox;
    private javax.swing.JCheckBox lightCheckbox;
    // End of variables declaration//GEN-END:variables
}
